<?php
namespace app\techn_api_n\controller\v1;
use app\common\logic\TechnLevelLogic;
use think\Db;
use think\Request;
use app\api\controller\v1\Mail;



class Sos extends Base
{
	public function _initialize()
	{
        parent::_initialize();
        $this->IsLogin(); //验证登录
        $this->IsTechn(); //验证技师


    }


    public function sos(Request $request){
        $techn = $this->techn;

        $order_info = Db::name('order')->where('techn_id',$techn['id'])->where('add_time','>',(time()-26400))->where('status','in','4,5,6')->order('id desc')->find();
        if (!empty($order_info)){
            $address = Db::name('order_address')->where('order_id',$order_info['id'])->find();
            if (!empty($address)){
                $address_name = $address['province_name'].$address['city_name'].$address['county_name'].$address['address'].$address['address_des'];
                $te = Db::name('techn')->where('id',$techn['id'])->find();
                $shi = $te['city'];
                $qu = $te['county'];
                $proxy = Db::name('proxy')->where('qu',$qu)->where('is_xian',1)->where('is_delete_time',0)->find();
                if (empty($proxy)){
                    $proxy = Db::name('proxy')->where('shi',$shi)->where('is_xian',0)->where('is_delete_time',0)->find();
                    $send = Db::name('email_list')->where('proxy_id','in',$proxy['proxy_id'].',999')->select();
                    $send = Db::name('email_list')->where('proxy_id','in',$proxy['proxy_id'].',999')->where('mobile','>',0)->column('mobile');
//                    $send = [15035514195];
//                    $send = '846315369@qq.com';
//                    $msg = $techn['nickname']."技师报警通知,<br>
//            技师上门地址为:".$address_name.",<br>
//            报警时间:".date('Y-m-d H:i',time())."<br>";
//
//                    Mail::mailTo($send,'技师报警通知',$msg);
                    $jinji = Db::name('techn')->where('id',$techn['id'])->value('sos_phone');
                    foreach ($send as $value){
                        $res_sms = aliyun_send_sms("LTAI5tCfyuqK4o58i6MH3qH2","xXOnPRM4tMimqDVR4e1Ms5crn0lUtP",$value,"摩小妹",'SMS_462660730',["name" => $techn['nickname'],"address"=>$address_name,"time"=>date('Y-m-d H:i',time()),"phone"=>$jinji]);

                    }
//                    dump($res_sms);
                    echo json_encode(['code'=>0,'msg'=>'已报警']);

            }


            }

        }else{
            echo json_encode(['code'=>0,'msg'=>'暂无报警订单']);

        }
    }




}